﻿using System;
using System.Collections.Generic;
using System.Text;
using App.Persistencia;

namespace App.Datos
{
    public class Facade
    {
        
        #region <<singleton>> Facade

        private static volatile Facade _instance = null;

        private static readonly object padlock = new object();

        public static Facade Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (padlock)
                    {
                        if (_instance == null)
                            _instance = new Facade();
                    }
                }
                return _instance;
            }
        }
        protected Facade() { }

        #endregion

        /**
         * Retorna una nueva instancia de la base de datos;
         */
        public App.Modelo.Interfaces.IRepositorio CreateRepositorio()
        {
            Repositorio dbh = new App.Persistencia.Repositorio();
            
            dbh.OpenSession();

            return dbh;
        }


        public App.Modelo.Interfaces.IRepositorio CreateRepositorio(NHibernate.ISession _Session)
        {
            Repositorio dbh = new App.Persistencia.Repositorio(_Session);

            dbh.OpenSession();

            return dbh;
        }
    }
}
